<h1>Quản lý bài viết</h1>


<form id="form" action="" method="post">

<div class="form-group">
    <div class="form-group">
        <!-- Single button -->
        <div class="btn-group">
            <select id="task" name="task" class="form-control">
                <option>Tác vụ</option>                
                <option value="delete">Xóa bài viết</option>
                <option value="deactive">Ẩn bài viết</option>
                <option value="active">Hiện bài viết</option>
            </select>
        </div>
        <a class="btn btn-primary" href="admin.php?r=articles/insert"><i class="glyphicon glyphicon-plus"></i> Thêm mới</a>
        <div class="btn-group pull-right">
            <input id="search" name="search" type="text" value="" class="form-control" placeholder="Tìm kiếm"/>
        </div>        
    </div>

</div>

<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <td><input id="check_all" type="checkbox" /></td>
            <td>ID</td>
            <td>Danh mục</td>
            <td>Name</td>
            
            <td>Create Time</td>
            <td>Status</td>
        </tr>            
    </thead>
    <tbody>
        <?php foreach($articles as $article) : ?>
        <tr>
            <td><input name="id[]" type="checkbox" value="<?php echo $article['id']; ?>" /></td>
            <td><?php echo $article['id']; ?></td>
            <td><?php echo $article['category']; ?></td>
            <td>
                <a href="admin.php?r=articles/update&id=<?php echo $article['id']; ?>"><?php echo htmlentities($article['name']); ?></a>
            </td>
            <td><?php echo $article['create_time']; ?></td>
            <td>
                <i class="<?php echo $article['status'] ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove'; ?>"></i>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>

</form>

<!-- Hiển thị phân trang -->
<?php echo $pagination; ?>

<script type="text/javascript">
    $(document).ready(function () {
        $('#check_all').change(function(){
            $('.table input:checkbox').prop('checked', this.checked);
        });
        $('#task').change(function(){
            var check = true;
            if ($(this).val()=="delete") {
                check = confirm('Có chắc bạn muốn xóa?');
            }
            if (check) {
                $('#form').submit();
            } else {
                $('#task option:first-child').prop('selected', true);
            }         
        });
        $('#search').keyup(function(e){
            if (e.which==13) {
                $('#form').submit();
            }                
        });
    });
</script>